// 2013-8-1下午12:38:00  net.betou.trade.main.manager.impl.UserExtMngImpl.java

package net.betou.trade.main.manager.impl;

import net.betou.common.hibernate3.Updater;
import net.betou.trade.entity.main.User;
import net.betou.trade.entity.main.UserExt;
import net.betou.trade.main.dao.UserExtDao;
import net.betou.trade.main.manager.UserExtMng;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 * @author 叶装装
 */
@Service
@Transactional
public class UserExtMngImpl implements UserExtMng{

	public UserExt save( UserExt ext, User bean ) {
		ext.blankToNull( );
		ext.setUser( bean );
		return dao.save( ext );
	}

	public UserExt update( UserExt ext, User bean ) {
		UserExt entity = dao.findById( bean.getId( ) );
		if( entity == null ){
			entity = save( ext, bean );
			bean.getExts( ).add( ext );
			return entity;
		}else{
			Updater< UserExt > updater = new Updater< UserExt >( ext );
			updater.include( "gender" );
			updater.include( "birthday" );
			ext = dao.updateByUpdater( updater );
			ext.blankToNull( );
			return ext;
		}
	}
	
	@Autowired
	private UserExtDao dao;

}
